package request;

import core.Constants;
import core.GameBoard;
import core.GameCharacter;
import core.GameMode;
import core.GameQuestion;
import core.GameUser;

import java.io.OutputStream;

import response.ResponseBoardQuestion;

/**
 * @author Gary
 */
public class RequestBoardQuestion extends GameRequest {


    // User Information
    private GameUser user;
    private GameCharacter character;
    // Request Information
    public static GameBoard gameBoard;
    private GameQuestion question;
    private boolean isValid;

    public RequestBoardQuestion() {
        code = Constants.CMSG_BOARD_QUESTION;
    }

    public void parse() {
        user = client.getUser();
        character = user.getCharacter();
        
        character.setGameMode(0);
        
        if (character.getGameMode() == 0) {
            character.setGameMode(2);

            GameMode mode = gameServer.getGameMode(character.getGameMode());
            

            //if (mode != null) {
                if (0 == Constants.GAME_MODE_BOARD) {
                    //gameBoard = (GameBoard) mode;
                    
                     gameBoard= new GameBoard(2, "2",null,(short) 0, "C210J01", (short)1, (short)6, null);
                     
                    //if (character.getID() == gameBoard.getCurrentPlayer().getID()) {
                        question = gameBoard.getNewQuestion(gameServer);
                        gameBoard.setQuestionTimer(question.getTime());

                        isValid = true;
                    //}
                }
            //}
        //}
    }
    }

    public void respond(OutputStream output) {
        gameServer.log("Server sending code: " + code, "d");
        ResponseBoardQuestion response = new ResponseBoardQuestion();
        response.set(gameServer);
        response.setOut(output);
        response.setDuration(1);
        response.setQuestion(question);
        response.run();

        gameServer.updateOthersQueue(response, gameServer.getActiveModeUserList(gameBoard.getID()), user.getID());
    }
}
